﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;

using NUnit.Framework;
using Boggle;

namespace Boggle.Tests
{
	/// <summary>
	/// A dictionary that is well behaved until after construction.
	/// </summary>
	public class MyGoodDictionary : IBoggleDictionary
	{
		#region IBoggleDictionary Members

		public string Name
		{
			get { throw new NotImplementedException(); }
		}

		public string Description
		{
			get { throw new NotImplementedException(); }
		}

		public bool IsDefineSupported
		{
			get { throw new NotImplementedException(); }
		}

		public bool IsWord(string word)
		{
			throw new NotImplementedException();
		}

		public List<string> Define(string word)
		{
			throw new NotImplementedException();
		}

		#endregion
	}

	/// <summary>
	/// A dictionary which throws an exception on construction.
	/// </summary>
	public class MyBadDictionary : MyGoodDictionary
	{
		public MyBadDictionary()
		{
			throw new Exception();
		}
	}

	/// <summary>
	/// A dictionary which requires a parameter for its constructor.
	/// </summary>
	public class MySecondBadDictionary : MyGoodDictionary
	{
		public MySecondBadDictionary(String someParam, String someOtherParam)
		{
		}
	}

	/// <summary>
	/// Tests the DictionaryEnumerator class.
	/// </summary>
	public class TestDictionaryEnumerator
	{
		/// <summary>
		/// Tests that we can load dictionaries from this assembly correctly.
		/// </summary>
		[Test]
		public void TestGetDictionaries()
		{
			var de = new DictionaryEnumerator(Assembly.GetExecutingAssembly());
			Assert.AreEqual(0, de.FailureMessages.Count);
			var dics = de.GetDictionaries().ToArray();
			Assert.AreEqual(1, dics.Length);
			Assert.AreEqual(typeof(MyGoodDictionary), dics[0].GetType());
			Assert.AreEqual(2, de.FailureMessages.Count);
			Assert.IsTrue(de.FailureMessages[0].Contains(typeof(MyBadDictionary).ToString()));
			Assert.IsTrue(de.FailureMessages[1].Contains(typeof(MySecondBadDictionary).ToString()));
		}

		/// <summary>
		/// Tests for an ArgumentNullException from the constructor of DictionaryEnumerator.
		/// </summary>
		[Test, ExpectedException(typeof(ArgumentNullException))]
		public void TestCtor()
		{
			new DictionaryEnumerator(null);
		}

		/// <summary>
		/// Tests that an appropriate exception is thrown when LoadDictionariesFromDirectory
		/// is called with a null directory.
		/// </summary>
		[Test, ExpectedException(typeof(ArgumentNullException))]
		public void TestLoadDictionariesFromDirectory()
		{
			DictionaryEnumerator.LoadDictionariesFromDirectory(null);
		}
	}
}
